package cn.itsource.org.mapper;

import cn.itsource.basic.util.GetUserInfoUtil;
import cn.itsource.org.domain.Employee;
import org.apache.ibatis.annotations.Select;
import tk.mybatis.mapper.common.Mapper;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

public interface EmployeeMapper extends Mapper<Employee> {

    //基础的crud通过继承得到
    List<Employee> findManagers();


    @Select("select * from t_employee where username = #{username} or email = #{email}  or phone = #{phone}")
    List<Employee> selectByUsernameByPhoneByEmail(Employee admin);


    @Select("select * from t_employee where username = #{username} or email = #{username}  or phone = #{username}")
    Employee selectByUsername(Employee employee);

    default List<Employee> findShopEmployees(){

        //1.拿到店铺id
        Long shopId = GetUserInfoUtil.getShopId();
        //2.封装条件
        Example example = new Example(Employee.class);
        example.and().andEqualTo("shopId", shopId);
        //3.查询
        return this.selectByExample(example);
    }
}
